<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh">
<head>
    <title>Title</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<!--对话框-->
<link rel="stylesheet" href="js/jconfirm/jquery-confirm.min.css">
<link rel="stylesheet" href="css/bootstrapValidator.css"/>


</head>
<body>
<!--左侧导航-->
<aside class="lyear-layout-sidebar">

  <!-- logo -->
  <div id="logo" class="sidebar-header">
    <a href="api/index.jsp"><img src="${pageContext.request.contextPath}/images/logo-zl.png" title="LightYear" alt="LightYear" /></a>
  </div>
  <div class="lyear-layout-sidebar-scroll">

    <nav class="sidebar-main">
      <ul class="nav nav-drawer">
        <li class="nav-item "> <a href="${pageContext.request.contextPath}/api/index"><i class="mdi mdi-home"></i> 后台首页</a></li>
        <li class="nav-item "> <a href="${pageContext.request.contextPath}/api/user"><i class="mdi mdi-account-multiple"></i> 用户管理</a></li>
        <li class="nav-item "> <a href="${pageContext.request.contextPath}/api/novel"><i class="mdi mdi-book-open-page-variant"></i> 小说管理</a></li>
        <li class="nav-item "> <a href="${pageContext.request.contextPath}/api/category"><i class="mdi mdi-server"></i> 类别管理</a></li>
        <li class="nav-item "> <a href="${pageContext.request.contextPath}/api/admin"><i class="mdi mdi-account-multiple"></i> 管理员管理</a></li>
        <li class="nav-item nav-item-has-subnav">
      </ul>
    </nav>

  </div>

</aside>
<!--End 左侧导航-->

<!--头部信息-->
<header class="lyear-layout-header">

  <nav class="navbar navbar-default">
    <div class="topbar">

      <div class="topbar-left">
        <div class="lyear-aside-toggler">
          <span class="lyear-toggler-bar"></span>
          <span class="lyear-toggler-bar"></span>
          <span class="lyear-toggler-bar"></span>
        </div>
        <span class="navbar-page-title">  </span>
      </div>

      <ul class="topbar-right">
        <li class="dropdown dropdown-profile">
          <a href="javascript:void(0)" data-toggle="dropdown">

            <span><span id="name"></span><span class="caret" ></span></span>
          </a>
          <ul class="dropdown-menu dropdown-menu-right">
            <li> <a href="javascript:void(0)" id="getAdmin" ><i class="mdi mdi-account"></i> 个人信息</a> </li>
            <li> <a href="javascript:void(0)" id="updateAdmin"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
            <li class="divider"></li>
            <li> <a href="javascript:void(0)" id="exit" ><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
          </ul>
        </li>
      </ul>

    </div>
  </nav>

</header>
<!--End 头部信息-->

<%--个人信息--%>
<div class="modal fade" id="admin-class" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" >个人信息</h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal"  action="lyear_forms_elements.html" method="post" onsubmit="return false;">
          <div class="form-group">
            <label class="col-md-3 control-label" for="adminid">账号：</label>
            <div class="col-md-7">
              <input class="form-control" type="text" readonly id="adminid"  >
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 control-label" for="adminusername">账号：</label>
            <div class="col-md-7">
              <input class="form-control" type="text" readonly id="adminusername" >
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 control-label"  for="adminpassword">密码：</label>
            <div class="col-md-7">
              <input class="form-control" type="text" readonly id="adminpassword" >
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<%--个人信息end--%>

<%--修改密码--%>
<div class="modal fade" id="password-class" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="clearForm()"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" >个人信息</h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal"  action="lyear_forms_elements.html" id="updateForm" method="post" onsubmit="return false;">
          <div class="form-group">
            <label class="col-md-3 control-label" for="oldpassword" >旧密码：</label>
            <div class="col-md-7">
              <input class="form-control" type="password" id="oldpassword" name="oldpassword" placeholder="请输入旧密码">
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 control-label" for="newpassword1" >新密码：</label>
            <div class="col-md-7">
              <input class="form-control" type="password" id="newpassword1" name="newpassword1" placeholder="请输入新密码">
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 control-label" for="newpassword2" placeholder="请输入再次输入新密码">新密码：</label>
            <div class="col-md-7">
              <input class="form-control" type="password" id="newpassword2" name="newpassword2" placeholder="请输入再次输入新密码">
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="clearForm()">关闭</button>
        <button type="button" class="btn btn-primary" id="update">修改</button>
      </div>
    </div>
  </div>
</div>
<%--修改密码end--%>


<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
<script src="js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="js/template-web.js"></script>
<script type="text/javascript" src="js/lightyear.js"></script>
<!--对话框-->
<script src="js/jconfirm/jquery-confirm.min.js"></script>
<!--图表插件-->
<script src="js/echarts.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>
<script type="text/javascript">
  function clearForm(){
    $("#updateForm").data('bootstrapValidator').resetForm(true);
    $("#oldpassword").val(null);
    $("#newpassword1").val(null);
    $("#newpassword2").val(null);
  }

  $("#exit").click(function (){
    $.confirm({
      title: '退出登录',
      content: '确定退出登录该账号',
      buttons: {
        confirm: {
          text: '确认',
          action: function(){
            $.ajax({
              url:"logout",
              type:"POST",
              dataType:"JSON",
              success:function (resp){
                if(resp.code===10000){
                  lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center','${pageContext.request.contextPath}/login.jsp' );
                }else {
                  lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
                }
              }
            })
          }
        },
        cancel: {
          text: '取消',
        },
      }
    });
  })

  $("#getAdmin").click(function (){
    $("#admin-class").modal("show");
    getAdmin();
  })

  $("#updateAdmin").click(function (){
    $("#password-class").modal("show");
  })

  $("#update").click(function (){
    $("#updateForm").data('bootstrapValidator').validate();//相当于触发一次所有的验证
    if($("#updateForm").data('bootstrapValidator').isValid()){//判断验证是否已经通过
      $.ajax({
        url:"api/common/update",
        type:"POST",
        data:{newPassword:$("#newpassword1").val(),oldPassword:$("#oldpassword").val()},
        dataType:"JSON",
        success:function (resp){
          if(resp.code===10000){
            $("#password-class").modal('hide');
            clearForm();
            lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
          }else {
            clearForm();
            lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
          }
        }
      })
    }
  })

  $(document).ready(function () {
    getAdmin();
  });
  function getAdmin(){
    $.ajax({
      url:"api/common/get",
      type:"GET",
      dataType:"JSON",
      success:function (resp){
        if(resp.code===10000){
          $("#name").text(resp.data.username);
          $("#adminid").val(resp.data.id);
          $("#adminusername").val(resp.data.username);
          $("#adminpassword").val(resp.data.password);
        }else {
        }
      }
    })
  }

  /**
   *下面就是bootstrapValidator的初始化
   *定义你需要的哪些表单需要验证，验证什么内容
   **/
  $("#updateForm").bootstrapValidator({
    feedbackIcons: {//这里是用来对应三种不同状态时，在输入框后面添加的图标
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },
    fields:{//哪些字段需要验证，和html中的输入框，下拉框等等表单name属性所对应。
      oldpassword:{
        validators:{//从这里也可以容易的看出可以有多个验证信息
          notEmpty:{//非空验证
            message:"请输入旧密码！！！" //提示信息，当你不写这里时它会自动的调用自带的提示信息，默认是英文，可导入language下的中文JS文件
          },
        }
      },
      newpassword1:{
        validators:{
          notEmpty:{
            message:"请输入新密码！！！"
          }
        }
      },
      newpassword2:{
        validators:{
          notEmpty:{
            message:"请输入验证码！！！"
          },
          identical: {//用来判断制定的字段和当前字段一致与否
            field: 'newpassword1',
            message: "两次输入的密码不一致！！！"
          }

        }
      }
    }
  });
</script>
</body>
</html>